﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Text;
using Common;

public partial class admin_system_enumdefeditor : PageBase
{
    public string PageTitle = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Expires = -1;
        PageBegin("system configuration");

        ///保存
        if (RequestBase.GetFormString("__EVENTTARGET") == "save")
        {
            SaveInfo();
        }

        if (!IsPostBack)
        { 
            if (RequestBase.GetQueryString("otype") == "modify")
            {
                PageTitle = "Modify";
                Initialize();
            }
            else
            {
                PageTitle = "Add"; 
            }
        }
    }

    #region 信息初始化
    void Initialize()
    {
        GetObj = BLL.Sys.EnumDef.GetObjById(RequestBase.GetQueryString("enumdefid"));
    }

    ///// <summary>
    ///// 信息实体
    ///// </summary>
    Model.Sys.EnumDef GetObj
    {
        get
        {
            Model.Sys.EnumDef _cat = new Model.Sys.EnumDef();
            if (!string.IsNullOrEmpty(RequestBase.GetQueryString("enumdefid").Trim()))
            {
                _cat.EnumDefId = RequestBase.GetQueryString("enumdefid");
            }
            _cat.EnumKey = txtEnumKey.Value.Trim();
            _cat.Title = txtTitle.Value.Trim();
            _cat.Type = txtType.Value.Trim();
            _cat.Description = txtDescription.Value.Trim(); 

            return _cat;
        }
        set
        {
            if (value != null)
            {
                txtEnumKey.Value = value.EnumKey.Trim();
                txtTitle.Value = value.Title.Trim(); 
                txtType.Value = value.Type.Trim(); 
                txtDescription.Value = value.Description; 
            }
        }
    }
    #endregion

    void SaveInfo()
    {
        string res = "";

        if (RequestBase.GetQueryString("otype").Trim() == "add")
        {

            res = BLL.Sys.EnumDef.Add(GetObj);
        }

        if (RequestBase.GetQueryString("otype").Trim() == "modify")
        {
            res = BLL.Sys.EnumDef.Update(GetObj);
        }

        switch (res)
        {
            case "succeeded":
                if (RequestBase.GetQueryString("otype") == "add")
                {
                    if (RequestBase.GetFormString("__EVENTARGUMENT") == "saveandclose")
                        JScript.AlertAndReturnValueToParent("Information saved successfully!", "window.opener.window.location.reload(); window.close();");
                    else
                        JScript.AlertAndRedirect("Information saved successfully!", "../system/enumdefeditor.aspx?otype=add");
                }
                else
                {
                    if (RequestBase.GetFormString("__EVENTARGUMENT") == "saveandclose")
                        JScript.AlertAndReturnValueToParent("Information saved successfully!", "window.opener.window.location.reload(); window.close();");
                    else
                        JScript.AlertAndRedirect("Information saved successfully!", "../system/enumdefeditor.aspx?otype=add=");
                }
                break;
            default:
                JScript.Alert(res);
                break;
        }
    }
}
